// 用户行为分析采集js
import store from '@/store'
import xeutils from 'xe-utils/methods/xe-utils'
import http from '@/utils/request'

export default {
  sendUserBehavior
}

/**
 * 发送行为日志
 * @param url
 * @param type 用户行为类型 菜单 按钮
 * @param action 动作
 * @param desc 动作描述
 */
export function sendUserBehavior (url, menuId, type, action, desc) {
  // let url = urlData
  let user = store.state.user
  let userBehavior = {
    userName: user.username,
    realName: user.realName,
    operaDate: xeutils.toDateString(new Date()),
    clientType: 'PC',
    operaType: type,
    operaUrl: url,
    operaMenuId: menuId,
    operaAction: action,
    operaDesc: desc
  }
  // 发送用户行为日志到后台服务
  http.post('/sys/sysLogUserBehavior/saveUserBehavior', userBehavior)
}
